<template>
  <div class="app-container" style="padding: 0 !important;">
    <el-form inline size="small" ref="queryForm" :model="queryParams" v-show="showSearch" label-width="100px">
      <el-form-item label="车牌号" prop="carNo">
        <el-input style="width:215px;" v-model="queryParams.carNo"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="list" border>
      <el-table-column label="车辆信息" prop="carNo" width="300"  align="center" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <div><b>{{scope.row.carNo}}</b></div>
          <div> {{ scope.row.combinedField }}</div>
        </template>
      </el-table-column>
      <el-table-column label="门店信息" prop="carNo" width="160"  align="center">
        <template slot-scope="scope">
          <div>归属:&nbsp;&nbsp;{{scope.row.belongingStoreName}}</div>
          <div>停靠:&nbsp;&nbsp;{{scope.row.locatedStoreName}}</div>
        </template>
      </el-table-column>
      <el-table-column label="车辆状态" align="center" prop="carStatus" min-width="120px">
        <template slot-scope="scope">
          <div>{{ carStatusFmt(scope.row) }}</div>
        </template>
      </el-table-column>
      <el-table-column prop="syDay" label="商业险信息" align="center" min-width="120px" :show-overflow-tooltip="true" v-if="type===22">
        <template slot-scope="{ row }">
            <span v-if="row.syType == 1" style="color: #00c585">
              在保
              <span style="white-space: nowrap">
                剩余&nbsp;{{ row.syDay }}&nbsp;天
              </span>
            </span>
          <span v-else-if="row.syType == 2" style="color: #ff4949">
              不在保
              <span style="white-space: nowrap">
                超&nbsp;{{ 0 - Number(row.syDay) }}&nbsp;天
              </span>
            </span>
          <span v-else-if="row.syType == 3" style="color: #ffb83b">
              即将到期
              <span style="white-space: nowrap">
                剩余&nbsp;{{ row.syDay }}&nbsp;天
              </span>
            </span>
          <span v-else>--</span>
        </template>
      </el-table-column>
      <el-table-column prop="jqDay" label="交强险信息" align="center" min-width="120px" :show-overflow-tooltip="true" v-if="type===23">
        <template slot-scope="{ row }">
            <span v-if="row.jqType == 1" style="color: #00c585">
              在保
              <span>剩余&nbsp;{{ row.jqDay }}&nbsp;天</span>
            </span>
          <span v-else-if="row.jqType == 2" style="color: #ff4949">
              不在保
              <span>超&nbsp;{{ 0 - Number(row.jqDay) }}&nbsp;天</span>
            </span>
          <span v-else-if="row.jqType == 3" style="color: #ffb83b">
              即将到期
              <span>剩余&nbsp;{{ row.jqDay }}&nbsp;天</span>
            </span>
          <span v-else>--</span>
        </template>
      </el-table-column>
      <el-table-column prop="useMileage" label="保养信息" align="center" min-width="180" :show-overflow-tooltip="true" v-if="type===24">
        <template slot-scope="{ row }">
            <span v-if="Number(row.nextMile) > Number(row.useMileage)" style="color: #00c585">
              已保养
              <span>
                距离下次保养{{
                  Number(row.nextMile) - Number(row.useMileage)
                }}km
              </span>
            </span>
          <span v-else-if="Number(row.nextMile) < Number(row.useMileage)" style="color: #ff4949">
              待保养
              <span>车辆里程已到保养标准</span>
            </span>
          <span v-else>--</span>
        </template>
      </el-table-column>
      <el-table-column prop="njDay" label="年检信息" align="center" min-width="120px" :show-overflow-tooltip="true"  v-if="type===25">
        <template slot-scope="{ row }">
            <span v-if="row.njType == 1" style="color: #00c585">
              已年检
              <span>剩余&nbsp;{{ row.njDay }}&nbsp;天</span>
            </span>
          <span v-else-if="row.njType == 2" style="color: #ff4949">
              已到期
              <span>超&nbsp;{{ 0 - Number(row.njDay) }}&nbsp;天</span>
            </span>
          <span v-else-if="row.njType == 3" style="color: #ffb83b">
              即将到期
              <span>剩余&nbsp;{{ row.njDay }}&nbsp;天</span>
            </span>
          <span v-else>--</span>
        </template>
      </el-table-column>

      <el-table-column label="操作" width="160" align="center">
        <template slot-scope="{row}" >
          <el-button type="text" v-if="type === 21" @click="handleCommand('carOffLine',row)">下线</el-button>
          <el-button type="text" v-if="type === 22" @click="handleCommand('sYrenewinsurance',row)">商业险续保</el-button>
          <el-button type="text" v-if="type === 23" @click="handleCommand('jqrenewinsurance',row)">交强险续保</el-button>
          <el-button type="text" v-if="type === 24" @click="handleCommand('vehicle',row)">维保</el-button>
          <el-button type="text" v-if="type === 25" @click="handleCommand('inspection',row)">年检</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :pageSizes="[5,10,15,20,50]" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />


  </div>
</template>

<script>
import { getCanDolist } from '@/api/car/car_basic'
import Template from "@/views/system/template";

export default {
  dicts: [],
  props: {
    type: {
      type: Number,
      default: 0,
    }
  },
  components:{
    Template,
  },
  data() {
    return {
      loading: false,
      list: [],
      // 总条数
      total: 0,
      // 显示搜索条件
      showSearch: true,
      queryParams: {
        carNo: "",//车牌号
        type: this.type,//车型id
        pageNum: 0,//页码   必选
        pageSize: 5,//每页显示数据 必选
      },
    };
  },
  mounted() {
    this.getList();
  },
  methods: {
    getList() {
      this.loading = true
      getCanDolist(this.queryParams).then(response => {
        this.list = response.rows;
        this.total=response.total;
        this.loading =false
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    handleCommand(command, row) {
      this.$emit("handleCommand",command, row)
    },
    carStatusFmt(row) {
      if (row.lineStatus == 0) {
        return '已下线'
      }
      if (row.transferStatus == 1) {
        return '车辆调出'
      }
      if (row.transferStatus == 3) {
        return '车辆调拨中'
      }
      if (row.carStatus == 1) {
        return '待整备'
      }
      if (row.carStatus == 2) {
        return '备发车'
      }
      if (row.carStatus == 3) {
        return '预定中'
      }
      if (row.carStatus == 4 || row.carStatus == 6) {
        return '用车中'
      }
      if (row.carStatus == 5) {
        return '同行借出'
      }
    },
  },
}
</script>
<style>
.sucess-text{
  color: #13ce66;font-size: 12px
}
.warning-text{
  color: #ffba00;font-size: 12px
}
.danger-text{
  color: #ff4949
}
</style>
